<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Hybrid Calculator: main.cpp File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Hybrid Calculator
   </div>
   <div id="projectbrief">Homework3 of D.S.A. Design a four-rule hybrid calculator.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('a00002.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">main.cpp File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Homework3 of D.S.A. Design a four-rule hybrid calculator.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;iostream&gt;</code><br />
<code>#include &lt;stack&gt;</code><br />
<code>#include &lt;queue&gt;</code><br />
<code>#include &lt;string&gt;</code><br />
<code>#include &lt;algorithm&gt;</code><br />
</div>
<p><a href="a00002_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ac006ef50ae5c9517970fdec10d0d7e7a"><td class="memItemLeft" align="right" valign="top"><a id="ac006ef50ae5c9517970fdec10d0d7e7a"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#ac006ef50ae5c9517970fdec10d0d7e7a">report_Error</a> ()</td></tr>
<tr class="memdesc:ac006ef50ae5c9517970fdec10d0d7e7a"><td class="mdescLeft">&#160;</td><td class="mdescRight">If the expression is illegal, then gives a error message and ends the program. <br /></td></tr>
<tr class="separator:ac006ef50ae5c9517970fdec10d0d7e7a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a589bcd938c8649eb74d23c687a923fc0"><td class="memItemLeft" align="right" valign="top"><a id="a589bcd938c8649eb74d23c687a923fc0"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#a589bcd938c8649eb74d23c687a923fc0">report_Error_zero</a> ()</td></tr>
<tr class="memdesc:a589bcd938c8649eb74d23c687a923fc0"><td class="mdescLeft">&#160;</td><td class="mdescRight">If a divisor in the expression is 0, then gives a error message and ends the program. <br /></td></tr>
<tr class="separator:a589bcd938c8649eb74d23c687a923fc0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acd83053f5df5d01d3fce0cd5e9c1dc21"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#acd83053f5df5d01d3fce0cd5e9c1dc21">Precedence</a> (char op)</td></tr>
<tr class="memdesc:acd83053f5df5d01d3fce0cd5e9c1dc21"><td class="mdescLeft">&#160;</td><td class="mdescRight">Determine the priority of the operator.  <a href="a00002.html#acd83053f5df5d01d3fce0cd5e9c1dc21">More...</a><br /></td></tr>
<tr class="separator:acd83053f5df5d01d3fce0cd5e9c1dc21"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a819fed027eb44c4137567e0ff82206e3"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#a819fed027eb44c4137567e0ff82206e3">calculate</a> (double num_1, double num_2, string op)</td></tr>
<tr class="memdesc:a819fed027eb44c4137567e0ff82206e3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate the result of the operation of two numbers.  <a href="a00002.html#a819fed027eb44c4137567e0ff82206e3">More...</a><br /></td></tr>
<tr class="separator:a819fed027eb44c4137567e0ff82206e3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0ff92f1f9adb92e5dd15180d26eb99c9"><td class="memItemLeft" align="right" valign="top">std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#a0ff92f1f9adb92e5dd15180d26eb99c9">remove_Invalid_Chars</a> (const std::string &amp;input)</td></tr>
<tr class="memdesc:a0ff92f1f9adb92e5dd15180d26eb99c9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Remove invalid characters from the input.  <a href="a00002.html#a0ff92f1f9adb92e5dd15180d26eb99c9">More...</a><br /></td></tr>
<tr class="separator:a0ff92f1f9adb92e5dd15180d26eb99c9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:abdf3fd66dae67912aae12fdd66498bd0"><td class="memItemLeft" align="right" valign="top">std::queue&lt; std::string &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#abdf3fd66dae67912aae12fdd66498bd0">Infix_To_Postfix</a> (const std::string &amp;infix)</td></tr>
<tr class="memdesc:abdf3fd66dae67912aae12fdd66498bd0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Converts an infix expression to a suffix expression.  <a href="a00002.html#abdf3fd66dae67912aae12fdd66498bd0">More...</a><br /></td></tr>
<tr class="separator:abdf3fd66dae67912aae12fdd66498bd0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ada088694e7a30f7bec22e39bc0161196"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#ada088694e7a30f7bec22e39bc0161196">calculate_Postfix</a> (const std::queue&lt; string &gt; &amp;postfix)</td></tr>
<tr class="memdesc:ada088694e7a30f7bec22e39bc0161196"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the value of the postfix expression.  <a href="a00002.html#ada088694e7a30f7bec22e39bc0161196">More...</a><br /></td></tr>
<tr class="separator:ada088694e7a30f7bec22e39bc0161196"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00002.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Homework3 of D.S.A. Design a four-rule hybrid calculator. </p>
<dl class="section author"><dt>Author</dt><dd>Han Yaoting </dd></dl>
<dl class="section date"><dt>Date</dt><dd>Fri Oct 27 2023 </dd></dl>

<p class="definition">Definition in file <a class="el" href="a00002_source.html">main.cpp</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a819fed027eb44c4137567e0ff82206e3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a819fed027eb44c4137567e0ff82206e3">&#9670;&nbsp;</a></span>calculate()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">double calculate </td>
          <td>(</td>
          <td class="paramtype">double&#160;</td>
          <td class="paramname"><em>num_1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">double&#160;</td>
          <td class="paramname"><em>num_2</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">string&#160;</td>
          <td class="paramname"><em>op</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculate the result of the operation of two numbers. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">num_1</td><td>1st number </td></tr>
    <tr><td class="paramname">num_2</td><td>2nd number </td></tr>
    <tr><td class="paramname">op</td><td>Operator </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>double Result of the operation </dd></dl>
<p>&lt; Check legitimacy</p>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00061">61</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">References <a class="el" href="a00002_source.html#l00022">report_Error()</a>, and <a class="el" href="a00002_source.html#l00032">report_Error_zero()</a>.</p>

<p class="reference">Referenced by <a class="el" href="a00002_source.html#l00214">calculate_Postfix()</a>.</p>

</div>
</div>
<a id="ada088694e7a30f7bec22e39bc0161196"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ada088694e7a30f7bec22e39bc0161196">&#9670;&nbsp;</a></span>calculate_Postfix()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">double calculate_Postfix </td>
          <td>(</td>
          <td class="paramtype">const std::queue&lt; string &gt; &amp;&#160;</td>
          <td class="paramname"><em>postfix</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the value of the postfix expression. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">postfix</td><td>The queue that stores the suffix expression </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>double Result of opreation </dd></dl>
<p>&lt; Number stack</p>
<p>&lt; Buffer of postfix queue</p>
<p>&lt; Take out the first string</p>
<p>&lt; Handle strings that are numbers</p>
<p>&lt; Check legitimacy</p>
<p>&lt; Calculations are made for each part</p>
<p>&lt; The psotfix expression is incorrect</p>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00214">214</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">References <a class="el" href="a00002_source.html#l00061">calculate()</a>, and <a class="el" href="a00002_source.html#l00022">report_Error()</a>.</p>

<p class="reference">Referenced by <a class="el" href="a00002_source.html#l00248">main()</a>.</p>

</div>
</div>
<a id="abdf3fd66dae67912aae12fdd66498bd0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abdf3fd66dae67912aae12fdd66498bd0">&#9670;&nbsp;</a></span>Infix_To_Postfix()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::queue&lt;std::string&gt; Infix_To_Postfix </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>infix</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Converts an infix expression to a suffix expression. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">infix</td><td>The infix expression string </td></tr>
    <tr><td class="paramname">postfix</td><td>The queue that stores the suffix expression </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true The conversion is successful </dd>
<dd>
false The conversion failed and the expression is invalid </dd></dl>
<p>&lt; Queue of Postfix</p>
<p>&lt; Stack of Opreator</p>
<p>&lt; Current Number</p>
<p>&lt; Check whether the nearest position exisits valid Number or not</p>
<p>&lt; Check whether the nearest position exisits valid Point or not</p>
<p>&lt; Check whether the nearest position exisits valid Operator or not</p>
<p>&lt; Check whether the nearest position exisits valid Left Bracket or not</p>
<p>&lt; Check whether the nearest position exisits valid Right Bracket or note</p>
<p>&lt; Check if the expression has point before we push the tem_Number or not</p>
<p>&lt; Check whether the expression is valid or not</p>
<p>&lt; Count the Number of Left Bracket</p>
<p>&lt; Count the Number of Right Bracket</p>
<p>&lt; If ch is a number from 1-9</p>
<p>&lt; Mark the number</p>
<p>&lt; Change the value of bool functions</p>
<p>&lt; Check legitimacy</p>
<p>&lt; Check legitimacy</p>
<p>&lt; push the tem_Number which is not empty into postfix_Queue</p>
<p>&lt; Remove all operators in the operator stack with a higher priority than the currently traversed operator ch and add to the postfix expression queue</p>
<p>&lt; Check legitimacy</p>
<p>&lt; Push left bracket into op_Stack</p>
<p>&lt; The number of left bracket +1</p>
<p>&lt; Check legitimacy</p>
<p>&lt; Push the expression in the bracket</p>
<p>&lt; Check legitimacy</p>
<p>&lt; Prevent individual numbers from being missed</p>
<p>&lt; Push the operator into postfix_Queue</p>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00097">97</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">References <a class="el" href="a00002_source.html#l00044">Precedence()</a>, and <a class="el" href="a00002_source.html#l00022">report_Error()</a>.</p>

<p class="reference">Referenced by <a class="el" href="a00002_source.html#l00248">main()</a>.</p>

</div>
</div>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&nbsp;</a></span>main()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int main </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>&lt; Get expression</p>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00248">248</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">References <a class="el" href="a00002_source.html#l00214">calculate_Postfix()</a>, <a class="el" href="a00002_source.html#l00097">Infix_To_Postfix()</a>, and <a class="el" href="a00002_source.html#l00081">remove_Invalid_Chars()</a>.</p>

</div>
</div>
<a id="acd83053f5df5d01d3fce0cd5e9c1dc21"></a>
<h2 class="memtitle"><span class="permalink"><a href="#acd83053f5df5d01d3fce0cd5e9c1dc21">&#9670;&nbsp;</a></span>Precedence()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int Precedence </td>
          <td>(</td>
          <td class="paramtype">char&#160;</td>
          <td class="paramname"><em>op</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Determine the priority of the operator. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">op</td><td>Operator </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>int Priority, the higher the number, the higher the priority </dd></dl>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00044">44</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">Referenced by <a class="el" href="a00002_source.html#l00097">Infix_To_Postfix()</a>.</p>

</div>
</div>
<a id="a0ff92f1f9adb92e5dd15180d26eb99c9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0ff92f1f9adb92e5dd15180d26eb99c9">&#9670;&nbsp;</a></span>remove_Invalid_Chars()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::string remove_Invalid_Chars </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>input</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Remove invalid characters from the input. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>The string given in input.txt </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>The string without invalid characters </dd></dl>

<p class="definition">Definition at line <a class="el" href="a00002_source.html#l00081">81</a> of file <a class="el" href="a00002_source.html">main.cpp</a>.</p>

<p class="reference">Referenced by <a class="el" href="a00002_source.html#l00248">main()</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="a00002.html">main.cpp</a></li>
    <li class="footer">Generated on Sun Dec 24 2023 20:35:28 for Hybrid Calculator by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
